package com.ias.gateway.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * 服务发现调试控制器
 * 
 * @author IAS Team
 * @since 1.0.0
 */
@RestController
@RequestMapping("/api/discovery")
public class DiscoveryController {

    @Autowired
    private DiscoveryClient discoveryClient;

    /**
     * 获取所有服务列表
     */
    @GetMapping("/services")
    public Mono<List<String>> getServices() {
        return Mono.just(discoveryClient.getServices());
    }

    /**
     * 获取指定服务的实例列表
     */
    @GetMapping("/services/{serviceId}/instances")
    public Mono<List<ServiceInstance>> getServiceInstances(@PathVariable String serviceId) {
        return Mono.just(discoveryClient.getInstances(serviceId));
    }

    /**
     * 健康检查
     */
    @GetMapping("/health")
    public Mono<String> health() {
        return Mono.just("Gateway Discovery is running");
    }
} 